<%--
  Created by IntelliJ IDEA.
  User: 11965
  Date: 2020/9/14
  Time: 8:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fm" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@include file="../header.jsp"%>
<script src="statics/calendar/WdatePicker.js"></script>
<div class="right">
    <div class="location">
        <strong>你现在所在的位置是:</strong>
        <span>用户管理页面 >> 用户修改页面</span>
    </div>
    <div class="providerAdd">
        <form id="userForm" name="userForm" method="post" action="${pageContext.request.contextPath}/userModify" enctype="multipart/form-data">
            <input type="hidden" name="id" value="${requestScope.user.id}" />
            <div>
                <label for="userName">用户编码：</label>
                <input type="text" value="${requestScope.user.usercode}" readonly="readonly">
            </div>
            <div>
                <label for="userName">用户名称：</label>
                <input type="text" name="username" id="userName" value="${requestScope.user.username}">
                <font color="red"></font>
            </div>
            <div>
                <label >用户性别：</label>
                <select name="gender" id="gender">

                    <option value="1" <c:if test="${requestScope.user.gender==1}">selected="selected"</c:if>>男</option>
                    <option value="0" <c:if test="${requestScope.user.gender==0}">selected="selected"</c:if>>女</option>

                </select>
            </div>
            <div>
                <label for="data">出生日期：</label>
                <input type="text" Class="Wdate" id="birthday" name="birthday" value="<fm:formatDate value="${requestScope.user.birthday}" pattern="yyyy-MM-dd"/>"
                       readonly="readonly" onclick="WdatePicker();">
                <font color="red"></font>
            </div>

            <div>
                <label for="userphone">用户电话：</label>
                <input type="text" name="phone" id="phone" value="${requestScope.user.phone}">
                <font color="red"></font>
            </div>
            <div>
                <label for="userAddress">用户地址：</label>
                <input type="text" name="address" id="address" value="${requestScope.user.address}">
            </div>
            <div>
                <label >用户角色：</label>
                <!-- 列出所有的角色分类 -->
                <input type="hidden" value="${requestScope.user.role.id}" id="selectid">
                <select name="role.id" id="userRole"></select>
                <font color="red"></font>
            </div>
            <div>
                <label for="m_idPicPath">证件照：</label>

                <input type="file" name="cardphotoFile" id="m_idPicPath"/>
                <font color="red"></font>

            </div>
            <div>
                <label for="m_workPicPath">工作证照片：</label>

                <input type="file" name="workphotoFile" id="m_workPicPath"/>
                <font color="red"></font>

            </div>
            <div class="providerAddBtn">
                <input type="button" name="save" id="save" value="保存" />
                <input type="button" id="back" name="back" value="返回"/>
            </div>
        </form>
    </div>
</div>
</section>
<script>
    $(function(){
        bindRole();

        bindEvent();
    })
    function bindRole(){
        //ajax请求 type=post
        //第一个参数为请求地址
        //第二个参数为请求的参数列表 （有则写，没有不写）
        //第三个参数 请求成功的回调函数
        //第四个参数为 响应数据类型 json
        $.post("/listRole",function(msg){
            var str = "";

            var selectid = $("#selectid").val();

            $(msg).each(function (i) {
                var r = msg[i];
                if(r.id == selectid){
                    str += "<option value='"+r.id+"' selected='selected'>"
                }else{
                    str += "<option value='"+r.id+"'>"
                }
                str += r.rolename
                str += "</option>"
            })
            $("#userRole").append(str);
        },"json")
    }

    function bindEvent(){
        $("#save").click(function(){
            //数据校验

            document.forms[0].submit();
        })
    }
</script>
<%@include file="../foot.jsp"%>